package com.example.a_lib.config;

import com.blankj.utilcode.util.SPUtils;
import com.example.a_lib.BuildConfig;

public  final  class ServerFlavorConfig {

    public static  String FLAVOR;
    public static   String API_BASE_URL_LEZHU_GENERAL;
    public static  String API_BASE_URL_IOT_GENERAL;

    public static    String API_SIGN_KEY ;
    public static      String BOS_BUCKET_LEZHU ;
    public static     String BOS_BUCKET_SMART_SITE ;
    public static     String CHECK_SERVICE_URL ;
    public static     String H5_HOST ;
    public static     String MINIPROGRAM_TYPE;
    public static     String NIM_APP_KEY;
    public static     String NIM_USER_PWD;
    public static     String WX_APP_ID;
    public static     String WX_APP_SECRET;
    public static     String TENCENT_FACE_LICENCE;
    public static     String TENCENT_FACE_APPID;
    public static     String WW_APP_ID;
    public static     String WW_APP_KEY;
    public static     String WW_AGENT_ID;
    public static     String WW_SCHEMA;
    /**
     * 根据用户选择的服务器环境策略分配服务器配置
     * @return 返回值 是 development 、staging 两个
     */
    public static String getSelectFlavorByStrategy(){
        if(ServerFlavorEnum.PRODUCTION.getValue().equals(BuildConfig.FLAVOR)){
            return ServerFlavorEnum.DEVELOPMENT.getValue();
        }else{
            //默认值是auto
            String USER_SELECT_FLAVOR_STRATEGY =  SPUtils.getInstance().getString("USER_SELECT_FLAVOR_STRATEGY", ServerFlavorEnum.AUTO.getValue());
            if(USER_SELECT_FLAVOR_STRATEGY.equals(ServerFlavorEnum.DEVELOPMENT.getValue())){
                return ServerFlavorEnum.DEVELOPMENT.getValue();
            }else if (USER_SELECT_FLAVOR_STRATEGY.equals(ServerFlavorEnum.STAGING.getValue())){
                return ServerFlavorEnum.STAGING.getValue();
            } else { //自动模式下使用安装包环境
                return BuildConfig.FLAVOR; //安装包环境由BuildConfig取得
            }
        }
    }

    /**
     * 根据用户切换的服务器，给用户切换配置文件，服务器切换只能在 development 和  staging 之间进行
     * ⚠️productFlavors.gradle 、 DevServerConfig和StagingServerConfig 三处配置文件要同步更改
     */

    public static void init(){
        String selectFlavor = getSelectFlavorByStrategy();
        if(ServerFlavorEnum.PRODUCTION.getValue().equals(BuildConfig.FLAVOR)){ //如果当前打包环境配置是正式服,数据以正式服数据为准
            applyBuildConfig();
        }else{ //如果当前打包环境配置非正式服 ，以用户选择的环境为准
            if (ServerFlavorEnum.DEVELOPMENT.getValue().equals(selectFlavor)){ //切换为开发服
                FLAVOR= DevServerConfig.FLAVOR;
                API_BASE_URL_LEZHU_GENERAL = DevServerConfig.API_BASE_URL_LEZHU_GENERAL;
                API_BASE_URL_IOT_GENERAL= DevServerConfig.API_BASE_URL_IOT_GENERAL;
                API_SIGN_KEY= DevServerConfig.API_SIGN_KEY;
                BOS_BUCKET_LEZHU= DevServerConfig.BOS_BUCKET_LEZHU;
                BOS_BUCKET_SMART_SITE= DevServerConfig.BOS_BUCKET_SMART_SITE;
                CHECK_SERVICE_URL= DevServerConfig.CHECK_SERVICE_URL;
                H5_HOST= DevServerConfig.H5_HOST;
                MINIPROGRAM_TYPE= DevServerConfig.MINIPROGRAM_TYPE;
                NIM_APP_KEY= DevServerConfig.NIM_APP_KEY;
                NIM_USER_PWD= DevServerConfig.NIM_USER_PWD;
                WX_APP_ID= DevServerConfig.WX_APP_ID;
                WX_APP_SECRET= DevServerConfig.WX_APP_SECRET;
                TENCENT_FACE_LICENCE= DevServerConfig.TENCENT_FACE_LICENCE;
                TENCENT_FACE_APPID= DevServerConfig.TENCENT_FACE_APPID;
                WW_APP_ID= DevServerConfig.WW_APP_ID;
                WW_APP_KEY= DevServerConfig.WW_APP_KEY;
                WW_AGENT_ID= DevServerConfig.WW_AGENT_ID;
                WW_SCHEMA= DevServerConfig.WW_SCHEMA;
            } else if (ServerFlavorEnum.STAGING.getValue().equals(selectFlavor)){ //切换为测试服
                FLAVOR= StagingServerConfig.FLAVOR;
                API_BASE_URL_LEZHU_GENERAL = StagingServerConfig.API_BASE_URL_LEZHU_GENERAL;
                API_BASE_URL_IOT_GENERAL= StagingServerConfig.API_BASE_URL_IOT_GENERAL;
                API_SIGN_KEY= StagingServerConfig.API_SIGN_KEY;
                BOS_BUCKET_LEZHU= StagingServerConfig.BOS_BUCKET_LEZHU;
                BOS_BUCKET_SMART_SITE= StagingServerConfig.BOS_BUCKET_SMART_SITE;
                CHECK_SERVICE_URL= StagingServerConfig.CHECK_SERVICE_URL;
                H5_HOST= StagingServerConfig.H5_HOST;
                MINIPROGRAM_TYPE= StagingServerConfig.MINIPROGRAM_TYPE;
                NIM_APP_KEY= StagingServerConfig.NIM_APP_KEY;
                NIM_USER_PWD= StagingServerConfig.NIM_USER_PWD;
                WX_APP_ID= StagingServerConfig.WX_APP_ID;
                WX_APP_SECRET= StagingServerConfig.WX_APP_SECRET;
                TENCENT_FACE_LICENCE= DevServerConfig.TENCENT_FACE_LICENCE;
                TENCENT_FACE_APPID= DevServerConfig.TENCENT_FACE_APPID;
                WW_APP_ID= StagingServerConfig.WW_APP_ID;
                WW_APP_KEY= StagingServerConfig.WW_APP_KEY;
                WW_AGENT_ID= StagingServerConfig.WW_AGENT_ID;
                WW_SCHEMA= StagingServerConfig.WW_SCHEMA;
            } else {
                applyBuildConfig();
            }
        }
    }

    /**
     * 使用打包时配置 （配置来自 BuildConfig）
     */
    static void applyBuildConfig(){
            FLAVOR= BuildConfig.FLAVOR;
            API_BASE_URL_LEZHU_GENERAL = BuildConfig.API_BASE_URL_LEZHU_GENERAL;
            API_BASE_URL_IOT_GENERAL= BuildConfig.API_BASE_URL_IOT_GENERAL;
            API_SIGN_KEY= BuildConfig.API_SIGN_KEY;
            BOS_BUCKET_LEZHU= BuildConfig.BOS_BUCKET_LEZHU;
            BOS_BUCKET_SMART_SITE= BuildConfig.BOS_BUCKET_SMART_SITE;
            CHECK_SERVICE_URL= BuildConfig.CHECK_SERVICE_URL;
            H5_HOST= BuildConfig.H5_HOST;
            MINIPROGRAM_TYPE= BuildConfig.MINIPROGRAM_TYPE;
            NIM_APP_KEY= BuildConfig.NIM_APP_KEY;
            NIM_USER_PWD= BuildConfig.NIM_USER_PWD;
            WX_APP_ID= BuildConfig.WX_APP_ID;
            WX_APP_SECRET= BuildConfig.WX_APP_SECRET;
            TENCENT_FACE_LICENCE= BuildConfig.TENCENT_FACE_LICENCE;
            TENCENT_FACE_APPID= BuildConfig.TENCENT_FACE_APPID;
            WW_APP_ID= BuildConfig.WW_APP_ID;
            WW_APP_KEY= BuildConfig.WW_APP_KEY;
            WW_AGENT_ID= BuildConfig.WW_AGENT_ID;
            WW_SCHEMA= BuildConfig.WW_SCHEMA;
    }

}
